package com.itheima.stock.config;

import com.itheima.stock.properties.StockJobProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version 1.0
 * @Author lwx
 * @Date 2024/12/29 8:44
 */
@Slf4j
@Configuration
public class ExecutorConfiguration {

    @Autowired
    private StockJobProperties stockJobProperties;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(stockJobProperties.getAdminAddress());
        xxlJobSpringExecutor.setAppname(stockJobProperties.getAppname());
        xxlJobSpringExecutor.setAddress(stockJobProperties.getExecutorAddress());
        xxlJobSpringExecutor.setIp(stockJobProperties.getExecutorIp());
        xxlJobSpringExecutor.setPort(stockJobProperties.getExecutorPort());
        xxlJobSpringExecutor.setAccessToken(stockJobProperties.getAccessToken());
        xxlJobSpringExecutor.setLogPath(stockJobProperties.getExecutorLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(stockJobProperties.getExecutorRetentionDays());

        return xxlJobSpringExecutor;
    }

}
